package com.nervenets.web.hibernate.dao;

import com.nervenets.web.hibernate.domain.AccountHold;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

@Repository
public interface AccountHoldDao extends JpaRepository<AccountHold, Long>, JpaSpecificationExecutor<AccountHold> {
    @Query("select new java.math.BigDecimal(coalesce(sum(money),0)) from AccountHold where user.id = :userId ")
    BigDecimal sumOfHoldBalance(@Param("userId") long userId);
}
